import java.util.List;
import java.util.Scanner;

public class WarGame extends CardGame {

	
	// Check for Maximum number of players
	@Override
	protected int getMaxPlayers() {
		return 0;
	}

	// Check for Minimum number of players
	@Override
	protected int getMinPlayers() {
		return 0;
	}

	// Initialize the number of players & create deck & score
	@Override
	protected void play(int numPlayers) {
		// Initialize players
		initPlayers(numPlayers);
		// Create new HoyleDeck
		deal(new HoyleDeck());
		// Come up with score for each player
		score();
	}

	// Creates players
	private void initPlayers(int numPlayers) {
		for (int i = 0; i < numPlayers; i++) {
			// This object . players class . add a new player (called
			// "Player 'i'")
			this.players.add(new Player("Player" + i));
		}
	}

	// Create a new deck object
	private void deal(HoyleDeck deck) {
		// Initialize variable
		int numDealt = 0;
		int cardRemainder = 0;

		// Determine cards to avoid dealing
		cardRemainder = 52 % players.size();
		System.out.println(cardRemainder);
		System.out.println(players.size());

		// Card is the number of cards in the deck
		Card card = deck.deal();

		// Deals cards
		for (int i = 52; i > cardRemainder; i--)
		// while (card >= cardRemainder)
		{
			// this . players list from Player class . get player number . run
			// Hand method . add card to that player's hand
			this.players.get(numDealt++ % players.size()).getHand().add(card);
			// Remove a card from the deck
			card = deck.deal();
		}
	}

	// Compute score for player "p"
	private void score() {
		for (Player p : this.players) {
			int playerScore = countHand(p.getHand());
			// System.out.println(cardCount);
			System.out.println(p.getName() + ": " + playerScore);
		}
		
	}

	/**
	 * Score a hand of cards. Computes a simple sum of points where each card
	 * gets the number of points equal to its face value (with J=11, Q=12, K=13)
	 * 
	 * @param hand
	 * @return score
	 */
	private int countHand(List<Card> hand) {
		int sum = 0;
		int cardCount = 0;
		for (Card card : hand) {
			sum += card.getFaceValue().ordinal() + 1;
			System.out.print(card.getFaceValue() + " " + card.getSuit()
					+ "   ||   ");
			cardCount++;
		}
		System.out.println();
		System.out.println(cardCount);
		return sum;
	}

	public int cardCount(List<Card> hand) {
		int cardCount = 0;
		for (Card card : hand) {
			cardCount++;
		}
		return cardCount;
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {

		// Receive number of players from user
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter the number of players: ");
		int numPlayers = sc.nextInt();
		System.out.println("You entered " + numPlayers + " number of players");

		// Start game
		new WarGame().play(numPlayers);
	}

	@Override
	protected void play() {
		// TODO Auto-generated method stub

	}

}
